﻿@page
@using SXFramWork.Web
@{
    ViewData["Title"] = "角色管理";
    Layout = AdminLayout.Pjax(HttpContext);
}
    <div id="container">


        <div class="list-wall">
            <div class="layui-form list-search">

                <button type="button" class="layui-btn layui-btn-sm layui-hide" data-type="reload">
                    <i class="layui-icon layui-icon-refresh"></i> 刷新
                </button>
                <button type="button" class="layui-btn layui-btn-normal" data-type="Add">
                    <i class="layui-icon layui-icon-add-circle"></i> 添加
                </button>
                <button type="button" class="layui-btn layui-btn-danger" data-type="Delete">
                    <i class="layui-icon"></i>
                    删除
                </button>

            </div>
            <table class="layui-hide" id="tablelist" lay-filter="tool"></table>


        </div>
        <script type="text/html" id="tool">
            <a class="layui-btn  layui-btn-warm " lay-event="edit" action-code="admin_sysuser_update"> 修改</a>
        </script>


        <script>
            layui.use(['table', 'layer', 'jquery', 'tree', 'common'],
                function () {
                    var table = layui.table,
                        layer = layui.layer,
                        $ = layui.jquery,
                        os = layui.common

                    //加载表格数据
                    os.tableRender({
                        elem: '#tablelist',
                        url: "/api/admin/sysrole/list",
                        cols: [
                            [
                                { type: 'checkbox', fixed: 'left' },
                                { field: 'name', title: '名称', sort: true, fixed: 'left' },
                                { field: 'remarks', title: '备注' },
                                { field: 'createTime', title: '创建时间' },
                                { title: '操作', width: 160, templet: '#tool' }
                            ]
                        ]
                    })

                    var active = {

                        reload: function () {
                            os.tableReload('tablelist',
                                { where: {} }
                            )
                        },

                        Add: function () {
                            os.Open('添加角色', '/admin/sysrole/add', '500px', '290px', function () {
                            });
                        },
                        Delete: function () {
                            var checkStatus = table.checkStatus('tablelist')
                                , data = checkStatus.data;
                            if (data.length === 0) {
                                os.error("请选择要删除的项目~");
                                return;
                            }
                            var str = '';
                            $.each(data, function (i, item) {

                                str += item.id + ",";

                            });
                           
                            layer.confirm('确定要执行批量删除吗？', function (index) {
                                layer.close(index);
                                os.ajax('api/admin/sysrole/delete/', str, function (res) {
                                    if (res.code === 1) {
                                        active.reload();
                                        os.success(res.msg);
                                    } else {
                                        os.error(res.msg);
                                    }
                                });
                            });

                        }
                    };


                    $('.list-search .layui-btn').on('click', function () {
                        var type = $(this).data('type');
                        active[type] ? active[type].call(this) : '';
                    });
                    //监听工具条
                    table.on('tool(tool)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'edit') {

                            os.Open('编辑角色', '/admin/sysrole/add/?id=' + data.id, '500px', '290px', function () {

                            })


                        }
                    });
                });
        </script>

    </div>